package com.cheer.controller;

import com.cheer.common.Result;
import com.cheer.param.AwardUpdateParam;
import com.cheer.service.ExMatchAwardService;
import com.cheer.vo.AwardListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author cheer
 */
@RestController
@RequestMapping("/lottery")
@Api(tags = "抽奖系统")
public class LotteryController {

    @Autowired
    private ExMatchAwardService exMatchAwardService;

    @ApiOperation("配置列表不分页 TODO (后续)")
    @PostMapping("/list")
    @PreAuthorize("@permissionValidator.isAdmin()")
    public Result<List<AwardListVO>> list(Integer act) {
        List<AwardListVO> lists = exMatchAwardService.list(act);
        return Result.success(lists);
    }

    @ApiOperation("奖品信息")
    @PostMapping("/info")
    @PreAuthorize("@permissionValidator.isAdmin()")
    public Result info(Integer id) {
        AwardListVO awardListVO = exMatchAwardService.info(id);
        return Result.success(awardListVO);
    }

    @ApiOperation("更新奖品信息 TODO (后续)")
    @PostMapping("/update")
    @PreAuthorize("@permissionValidator.isAdmin()")
    public Result update(@RequestBody @Valid AwardUpdateParam awardParam) {
        exMatchAwardService.update(awardParam);
        return Result.success();
    }

    @ApiOperation("参与情况导出")
    @GetMapping("/export")
    public void exportMatchHistory() {
        exMatchAwardService.exportMatchHistory();
    }

    @GetMapping("/prize/export")
    @ApiOperation("中奖情况导出")
    public void exportPrize() {
        exMatchAwardService.exportPrize();
    }

}
